package com.punai.externalccb.service;

import cn.hutool.core.collection.CollUtil;
import com.punai.common.bos.RestBodyResponse;
import com.punai.common.config.RuoYiConfig;
import com.punai.common.core.text.Convert;
import com.punai.common.properties.SqliteUpPathConfig;
import com.punai.common.utils.NumberUtil;
import com.punai.common.utils.StringUtil;
import com.punai.common.utils.sqlite.SqliteUtil;
import com.punai.externalccb.bo.*;
import com.punai.externalccb.constants.CCBConstants;
import com.punai.externalccb.constants.ZipUtil;
import com.punai.externalccb.domain.*;
import com.punai.externalccb.mapper.*;
import com.punai.prodatalibrary.domain.LibProject;
import com.punai.prodatalibrary.domain.ProjectInfoAttachment;
import com.punai.prodatalibrary.mapper.LibProjectMapper;
import com.punai.prodatalibrary.mapper.ProjectInfoAttachmentMapper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CCBUploadService {

    @Autowired
    private ProjectInfoAttachmentMapper projectInfoAttachmentMapper;
    @Autowired
    private LibProjectMapper libProjectMapper;


    @Autowired
    private SqliteUpPathConfig sqliteUpPathConfig;

    @Transactional
    public RestBodyResponse uploadCbCostSqliteFile(String proId, String type, InputStream inputStream, String checkType, String fileName) {
        Date uploadDate = new Date();
        String costTemplateUploadPath = sqliteUpPathConfig.getCcbpath();
        File newFile = new File(costTemplateUploadPath,"CostTempl_" + DateFormatUtils.format(uploadDate, "yyyyMMddHHmmssSSS"));
        try {
            FileUtils.copyInputStreamToFile(inputStream, newFile);
        } catch (IOException e) {
            e.printStackTrace();
            return RestBodyResponse.fail("上传失败!",e.getMessage());
        }
        if ( newFile.length() < 1 ) {
            // 文件里啥都没有
            return RestBodyResponse.fail("上传失败!","文件为空");
        }
        SqliteUtil sqliteUtil = new SqliteUtil();
        // 绝对路径
        String absolutePath = newFile.getAbsolutePath();
        sqliteUtil.getConnection(absolutePath);
        String filePath = costTemplateUploadPath + "/" + "CostTempl_" + DateFormatUtils.format(uploadDate, "yyyyMMddHHmmssSSS");
        // 项目附件
        ProjectInfoAttachment attachment = new ProjectInfoAttachment();
        attachment.setProjectId(proId);
        attachment.setAttachmentName(fileName);
        attachment.setAttachmentType(type);
        attachment.setUploadTime(uploadDate);
        attachment.setLocalFilePath(filePath);
        projectInfoAttachmentMapper.insert(attachment);

        LibProject project = libProjectMapper.selectById(proId);
        parseCbbDataToBd(sqliteUtil,project,type);
        if(CCBConstants.CCB_TYPE.MBZRCB.getCode().equals(type)){
            //02类型 关联目标责任成本 和 开工预算  所以给开工预算也保存数据(本可以删除KGYSSJ枚举，但其他地方有使用)
            parseCbbDataToBd(sqliteUtil,project,CCBConstants.CCB_TYPE.KGYSSJ.getCode());
        }
        if(CCBConstants.CCB_TYPE.JGCBFX.getCode().equals(type)){
            //04类型关联竣工成本分析和竣工结算  可以传ccb 所以给竣工结算也保存数据(本可以删除JGJSSJ枚举，但其他地方有使用)
            parseCbbDataToBd(sqliteUtil,project,CCBConstants.CCB_TYPE.JGJSSJ.getCode());
        }
        return RestBodyResponse.ok("上传成功!","","OK");
    }

    @Autowired
    private EcoBidnodeMapper bidnodeMapper;
    @Autowired
    private EcoBqitemMapper bqitemMapper;
    @Autowired
    private EcoBqitemmateMapper bqitemmateMapper;
    @Autowired
    private EcoBqitemzbinfoMapper bqitemzbinfoMapper;
    @Autowired
    private EcoCbbidnodeMapper cbbidnodeMapper;
    @Autowired
    private EcoCbfeeitemMapper cbfeeitemMapper;
    @Autowired
    private EcoCbfeeitemzbinfoMapper cbfeeitemzbinfoMapper;
    @Autowired
    private EcoCbinfoMapper cbinfoMapper;
    @Autowired
    private EcoCbsummaryMapper cbsummaryMapper;
    @Autowired
    private EcoCbsummaryzylrlMapper cbsummaryzylrlMapper;
    @Autowired
    private EcoCbtabinfoMapper cbtabinfoMapper;
    @Autowired
    private EcoCbzbitemMapper cbzbitemMapper;
    @Autowired
    private EcoContractinfoMapper contractinfoMapper;
    @Autowired
    private EcoCostuploadMapper costuploadMapper;
    @Autowired
    private EcoLmmdetailMapper lmmdetailMapper;
    @Autowired
    private EcoMeasureitemMapper measureitemMapper;
    @Autowired
    private EcoOtheritemMapper otheritemMapper;
    @Autowired
    private EcoProjectsgjxMapper projectsgjxMapper;
    @Autowired
    private EcoResourceMapper resourceMapper;
    @Autowired
    private EcoResourcezbinfoMapper resourcezbinfoMapper;
    @Autowired
    private EcoSummaryMapper summaryMapper;
    @Autowired
    private EcoXmhzMapper xmhzMapper;
    @Autowired
    private EcoZbstructitemMapper ecoZbstructitemMapper;
    @Autowired
    private EcoSecondaryMapper secondaryMapper;
    @Autowired
    private EcoCostanalysisMapper ecoCostanalysisMapper;


    public void parseCbbDataToBd(SqliteUtil sqliteUtil, LibProject project, String type) {
        String proId = project.getId();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String strCbSql = "select * from Summary";
        List<Summary> summaryList = sqliteUtil.selectListRecord(Summary.class, strCbSql);
        List<EcoSummary> summaries = new ArrayList<>();
        for (Summary summary : summaryList) {
            EcoSummary one=new EcoSummary();
            one.setOid(summary.getId());
            one.setCode(summary.getCode());
            one.setName(summary.getName());
            one.setOrdcode(summary.getOrdCode());
            one.setCalcbase(summary.getCalcBase());
            one.setCalctotal(summary.getCalcTotal());
            one.setRate(summary.getRate());
            one.setTotal(summary.getTotal());
            one.setKind(summary.getKind());
            one.setBidnodeid(summary.getBidNodeID());
            one.setDwbidnodeid(summary.getDwBidNodeID());
            one.setTaxrate(summary.getTaxRate());
            one.setStagetype(type);
            one.setProId(proId);
            summaries.add(one);
        }
        summaryMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(summaries)) {
            summaryMapper.insertBatchSomeColumn(summaries);
        }


        String strSql = "select hz.* from ZBStructItem hz";
        List<ZBStructItemBO> zbStructItemBOList = sqliteUtil.selectListRecord(ZBStructItemBO.class, strSql);

        List<EcoZbstructitem> zbStructItemList =new ArrayList<>();
        for (ZBStructItemBO zbStructItemBO : zbStructItemBOList) {
            strSql = "select zb.* from ZBStructItem zb where zb.ID ='"+zbStructItemBO.getPID()+"'";
            EcoZbstructitem zbStructItem = new EcoZbstructitem();
            zbStructItem.setZbid(zbStructItemBO.getID());
            try {
                ZBStructItemBO selectOneRecord = sqliteUtil.selectOneRecord(ZBStructItemBO.class, strSql);
                if(selectOneRecord==null){
                    zbStructItem.setZbpid(null);
                }else{
                    zbStructItem.setZbpid(zbStructItemBO.getPID());
                }
            } catch (Exception e) {
                zbStructItem.setZbpid(null);
            }
            zbStructItem.setName(zbStructItemBO.getName());
            zbStructItem.setUnit(zbStructItemBO.getUnit());
            zbStructItem.setJskj(zbStructItemBO.getJskj());
            zbStructItem.setJskjz(zbStructItemBO.getJskjz());
            zbStructItem.setDwzj(zbStructItemBO.getDwzj());
            zbStructItem.setZb(zbStructItemBO.getZb());
            zbStructItem.setCoefficient(zbStructItemBO.getCoefficient());
            zbStructItem.setCoefficientcb(zbStructItemBO.getCoefficientCB());
            zbStructItem.setStructid(zbStructItemBO.getStructID());
            zbStructItem.setBidnodeid(zbStructItemBO.getBidNodeID());
            zbStructItem.setYstotal(zbStructItemBO.getYsTotal());
            zbStructItem.setCbtotal(zbStructItemBO.getCbTotal());
            zbStructItem.setYsquantity(zbStructItemBO.getYsQuantity());
            zbStructItem.setCbquantity(zbStructItemBO.getCbQuantity());
            zbStructItem.setDatatype(zbStructItemBO.getDataType());
            zbStructItem.setDwcb(zbStructItemBO.getDwcb());
            zbStructItem.setKeyid(zbStructItemBO.getKeyID());
            zbStructItem.setProId(proId);
            zbStructItem.setReltype(zbStructItemBO.getRelType());
            zbStructItem.setStructname(zbStructItemBO.getStructName());
            zbStructItem.setShowtype(zbStructItemBO.getShowType());
            zbStructItem.setJzgcdwzj(zbStructItemBO.getJzgcdwzj());
            zbStructItem.setJzgczb(zbStructItemBO.getJzgczb());
            zbStructItem.setJzgcystotal(zbStructItemBO.getJzgcystotal());
            zbStructItem.setJzgcdj(zbStructItemBO.getJzgcdj());

            zbStructItem.setZsgcdwzj(zbStructItemBO.getZsgcdwzj());
            zbStructItem.setZsgczb(zbStructItemBO.getZsgczb());
            zbStructItem.setZsgcystotal(zbStructItemBO.getZsgcystotal());
            zbStructItem.setZsgcdj(zbStructItemBO.getZsgcdj());

            zbStructItem.setAzgcdwzj(zbStructItemBO.getAzgcdwzj());
            zbStructItem.setAzgczb(zbStructItemBO.getAzgczb());
            zbStructItem.setAzgcystotal(zbStructItemBO.getAzgcystotal());
            zbStructItem.setAzgcdj(zbStructItemBO.getAzgcdj());

            zbStructItem.setSzgcdwzj(zbStructItemBO.getSzgcdwzj());
            zbStructItem.setSzgczb(zbStructItemBO.getSzgczb());
            zbStructItem.setSzgcystotal(zbStructItemBO.getSzgcystotal());
            zbStructItem.setSzgcdj(zbStructItemBO.getSzgcdj());

            zbStructItem.setAmount(zbStructItemBO.getAmount());
            zbStructItem.setStagetype(type);
            zbStructItemList.add(zbStructItem);
        }
        ecoZbstructitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(zbStructItemList)) {
            ecoZbstructitemMapper.insertBatchSomeColumn(zbStructItemList);
        }


        strSql = " select hz.* from BidNode hz";
        List<BidNodeBO> bidNodeBOList = sqliteUtil.selectListRecord(BidNodeBO.class, strSql);
        List<EcoBidnode> bidNodeList =new ArrayList<>();
        for (BidNodeBO bidNodeBO : bidNodeBOList) {
            EcoBidnode convert = EcoBidnode.convert(bidNodeBO, type, project);
            convert.setStagetype(type);
            bidNodeList.add(convert);
        }
        bidnodeMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(bidNodeList)) {
            bidnodeMapper.insertBatchSomeColumn(bidNodeList);
        }

        strSql = "select hz.* from CbBidNode hz";
        List<CbBidNodeBO> cbBidNodeBOList = sqliteUtil.selectListRecord(CbBidNodeBO.class, strSql);
        List<EcoCbbidnode> cbBidNodeList =new ArrayList<>();
        for (CbBidNodeBO cbBidNodeBO : cbBidNodeBOList) {
            EcoCbbidnode cbBidNode = new EcoCbbidnode();
            cbBidNode.setBidnodeid(cbBidNodeBO.getID());
            cbBidNode.setPid(cbBidNodeBO.getPID());
            cbBidNode.setNodecode(cbBidNodeBO.getNodeCode());
            cbBidNode.setNodename(cbBidNodeBO.getNodeName());
            cbBidNode.setNodeidxcode(cbBidNodeBO.getNodeIdxCode());
            cbBidNode.setNodeidx(cbBidNodeBO.getNodeIdx());
            cbBidNode.setAmount(cbBidNodeBO.getAmount());
            cbBidNode.setFbqdrate(cbBidNodeBO.getFBQDRate());
            cbBidNode.setCsrate(cbBidNodeBO.getCSRate());
            cbBidNode.setQtrate(cbBidNodeBO.getQTRate());
            cbBidNode.setGfrate(cbBidNodeBO.getGFRate());
            cbBidNode.setSjrate(cbBidNodeBO.getSJRate());
            cbBidNode.setNodetype(cbBidNodeBO.getNodeType());
            cbBidNode.setTrade(cbBidNodeBO.getTrade());
            cbBidNode.setVisible(cbBidNodeBO.getVisible()?"Y":"N");
            cbBidNode.setFjsrate(cbBidNodeBO.getFJSRate());
            cbBidNode.setAqwmrate(cbBidNodeBO.getAQWMRate());
            cbBidNode.setYlfrate(cbBidNodeBO.getYLFRate());
            cbBidNode.setZjcsrate(cbBidNodeBO.getZJCSRate());
            cbBidNode.setProId(proId);
            cbBidNode.setStagetype(type);
            cbBidNodeList.add(cbBidNode);
        }
        cbbidnodeMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(cbBidNodeList)) {
            cbbidnodeMapper.insertBatchSomeColumn(cbBidNodeList);
        }
        strSql = "select hz.* from BQItemZBInfo hz";
        List<BQItemZBInfoBO> bQItemZBInfoBOList = sqliteUtil.selectListRecord(BQItemZBInfoBO.class, strSql);
        List<EcoBqitemzbinfo> bQItemZBInfoList =new ArrayList<>();
        for (BQItemZBInfoBO bQItemZBInfoBO : bQItemZBInfoBOList) {
            EcoBqitemzbinfo bQItemZBInfo = new EcoBqitemzbinfo();
            bQItemZBInfo.setBqitemzbinfoid(bQItemZBInfoBO.getID());
            bQItemZBInfo.setBqitemid(bQItemZBInfoBO.getBQItemID());
            bQItemZBInfo.setReltype(bQItemZBInfoBO.getRelType());
            bQItemZBInfo.setStructid(bQItemZBInfoBO.getStructID());
            bQItemZBInfo.setItemid(bQItemZBInfoBO.getItemID());
            bQItemZBInfo.setItemname(bQItemZBInfoBO.getItemName());
            bQItemZBInfo.setBidnodeid(bQItemZBInfoBO.getBidNodeID());
            bQItemZBInfo.setGclxs(bQItemZBInfoBO.getGclxs());
            bQItemZBInfo.setJsquantity(bQItemZBInfoBO.getJsQuantity());
            bQItemZBInfo.setProId(proId);
            bQItemZBInfo.setStagetype(type);
            bQItemZBInfoList.add(bQItemZBInfo);
        }
        bqitemzbinfoMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(bQItemZBInfoList)) {
            bqitemzbinfoMapper.insertBatchSomeColumn(bQItemZBInfoList);
        }

        strSql = "select hz.* from ResourceZBInfo hz";
        List<ResourceZBInfoBO> resourceZBInfoBOList = sqliteUtil.selectListRecord(ResourceZBInfoBO.class, strSql);
        List<EcoResourcezbinfo> resourceZBInfoList =new ArrayList<>();
        for (ResourceZBInfoBO resourceZBInfoBO : resourceZBInfoBOList) {
            EcoResourcezbinfo resourceZBInfo = new EcoResourcezbinfo();
            resourceZBInfo.setResourcezbinfoid(resourceZBInfoBO.getID());
            resourceZBInfo.setResourceid(resourceZBInfoBO.getResourceID());
            resourceZBInfo.setReltype(resourceZBInfoBO.getRelType());
            resourceZBInfo.setStructid(resourceZBInfoBO.getStructID());
            resourceZBInfo.setItemid(resourceZBInfoBO.getItemID());
            resourceZBInfo.setItemname(resourceZBInfoBO.getItemName());
            resourceZBInfo.setBidnodeid(resourceZBInfoBO.getBidNodeID());
            resourceZBInfo.setGclxs(resourceZBInfoBO.getGclxs());
            resourceZBInfo.setJsquantity(resourceZBInfoBO.getJsQuantity());
            resourceZBInfo.setProId(proId);
            resourceZBInfo.setStagetype(type);
            resourceZBInfoList.add(resourceZBInfo);
        }
        resourcezbinfoMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(resourceZBInfoList)) {
            resourcezbinfoMapper.insertBatchSomeColumn(resourceZBInfoList);
        }

        strSql = "select hz.* from BQItem hz";
        List<BQItemBO> BQItemBOList = sqliteUtil.selectListRecord(BQItemBO.class, strSql);
        List<EcoBqitem> bQItemList =new ArrayList<>();
        for (BQItemBO bQItemBO : BQItemBOList) {
            EcoBqitem bqItem=new EcoBqitem();
            bqItem.setBqitemid(bQItemBO.getID());
            bqItem.setBqitempid(bQItemBO.getPID());
            bqItem.setCode(bQItemBO.getCode());
            bqItem.setDescription(bQItemBO.getDescription());
            bqItem.setSpec(bQItemBO.getSpec());
            bqItem.setUnit(bQItemBO.getUnit());
            bqItem.setQuantity(bQItemBO.getQuantity());
            bqItem.setWorkscope(bQItemBO.getWorkScope());
            bqItem.setLaborrate(bQItemBO.getLaborRate());
            bqItem.setMaterialrate(bQItemBO.getMaterialRate());
            bqItem.setMachinerate(bQItemBO.getMachineRate());
            bqItem.setOverheadrate(bQItemBO.getOverheadRate());
            bqItem.setProfitrate(bQItemBO.getProfitRate());
            bqItem.setLevyfeerate(bQItemBO.getLevyFeeRate());
            bqItem.setTaxrate(bQItemBO.getTaxRate());
            bqItem.setRate(bQItemBO.getRate());
            bqItem.setItemtype(bQItemBO.getItemType());
            bqItem.setBidnodeid(bQItemBO.getBidNodeID());
            bqItem.setDwbidnodeid(bQItemBO.getDwBidNodeID());
            bqItem.setFbms(bQItemBO.getFbms());
            bqItem.setQdtype(bQItemBO.getQdType());
            bqItem.setBackcolor(bQItemBO.getBackColor());
            bqItem.setPx(bQItemBO.getPX());
            bqItem.setOrgfb(bQItemBO.getOrgFB());
            bqItem.setStandardfb(bQItemBO.getStandardFB());
            bqItem.setOrgname(bQItemBO.getOrgName());
            bqItem.setIscf(bQItemBO.getIsCf()?"Y":"N");
            bqItem.setIsadded(bQItemBO.getIsAdded()?"Y":"N");
            bqItem.setTargetamountexp(bQItemBO.getTargetAmountExp());
            bqItem.setZcmaterialrate(bQItemBO.getZcMaterialRate());
            bqItem.setFcmaterialrate(bQItemBO.getFcMaterialRate());
            bqItem.setZymachinerate(bQItemBO.getZyMachineRate());
            bqItem.setDxmachinerate(bQItemBO.getDxMachineRate());
            bqItem.setQtmachinerate(bQItemBO.getQtMachineRate());
            bqItem.setXjlaborrate(bQItemBO.getXJLaborRate());
            bqItem.setXjmaterialrate(bQItemBO.getXJMaterialRate());
            bqItem.setXjmachinerate(bQItemBO.getXJMachineRate());
            bqItem.setXjrate(bQItemBO.getXJRate());
            bqItem.setXjquantity(bQItemBO.getXJQuantity());
            bqItem.setSfzj(bQItemBO.getSfZj()?"Y":"N");
            bqItem.setContractcode(bQItemBO.getContractCode());
            bqItem.setIsnewdata(bQItemBO.getIsNewData());
            bqItem.setFcrate(bQItemBO.getFcRate());
            bqItem.setQtjxrate(bQItemBO.getQTjxRate());
            bqItem.setGlrate(bQItemBO.getGlRate());
            bqItem.setLrrate(bQItemBO.getLrRate());
            bqItem.setCategoryid(bQItemBO.getCategoryID());
            bqItem.setCbtotal(bQItemBO.getCBTotal());
            bqItem.setOriginalunit(bQItemBO.getOriginalUnit());
            bqItem.setProId(proId);
            bqItem.setStagetype(type);
            bQItemList.add(bqItem);
        }
        bqitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(bQItemList)) {
            bqitemMapper.insertBatchSomeColumn(bQItemList);
        }

        strSql = "select hz.* from MeasureItem hz";
        List<MeasureItemBO> measureItemBOList = sqliteUtil.selectListRecord(MeasureItemBO.class, strSql);
        List<EcoMeasureitem> measureItemList =new ArrayList<>();
        for (MeasureItemBO measureItemBO : measureItemBOList) {
            EcoMeasureitem measureItem=new EcoMeasureitem();
            measureItem.setMeasureitemid(measureItemBO.getID());
            measureItem.setMeasureitempid(measureItemBO.getPID());
            measureItem.setCode(measureItemBO.getCode());
            measureItem.setDescription(measureItemBO.getDescription());
            measureItem.setSpec(measureItemBO.getSpec());
            measureItem.setUnit(measureItemBO.getUnit());
            measureItem.setQuantity(measureItemBO.getQuantity());
            measureItem.setWorkscope(measureItemBO.getWorkScope());
            measureItem.setLaborrate(measureItemBO.getLaborRate());
            measureItem.setMaterialrate(measureItemBO.getMaterialRate());
            measureItem.setMachinerate(measureItemBO.getMachineRate());
            measureItem.setOverheadrate(measureItemBO.getOverheadRate());
            measureItem.setProfitrate(measureItemBO.getProfitRate());
            measureItem.setLevyfeerate(measureItemBO.getLevyFeeRate());
            measureItem.setTaxrate(measureItemBO.getTaxRate());
            measureItem.setRate(measureItemBO.getRate());
            measureItem.setItemtype(measureItemBO.getItemType());
            measureItem.setBidnodeid(measureItemBO.getBidNodeID());
            measureItem.setFbms(measureItemBO.getFbms());
            measureItem.setQdtype(measureItemBO.getQdType());
            measureItem.setBackcolor(measureItemBO.getBackColor());
            measureItem.setPx(measureItemBO.getPX());
            measureItem.setOrgfb(measureItemBO.getOrgFB());
            measureItem.setStandardfb(measureItemBO.getStandardFB());
            measureItem.setOrgname(measureItemBO.getOrgName());
            measureItem.setIscf(measureItemBO.getIsCf()?"Y":"N");
            measureItem.setIsadded(measureItemBO.getIsAdded()?"Y":"N");
            measureItem.setTargetamountexp(measureItemBO.getTargetAmountExp());
            measureItem.setZcmaterialrate(measureItemBO.getZcMaterialRate());
            measureItem.setFcmaterialrate(measureItemBO.getFcMaterialRate());
            measureItem.setZymachinerate(measureItemBO.getZyMachineRate());
            measureItem.setDxmachinerate(measureItemBO.getDxMachineRate());
            measureItem.setQtmachinerate(measureItemBO.getQtMachineRate());
            measureItem.setXjlaborrate(measureItemBO.getXJLaborRate());
            measureItem.setXjmaterialrate(measureItemBO.getXJMaterialRate());
            measureItem.setXjmachinerate(measureItemBO.getXJMachineRate());
            measureItem.setXjrate(measureItemBO.getXJRate());
            measureItem.setXjquantity(measureItemBO.getXJQuantity());
            measureItem.setSfzj(measureItemBO.getSfZj()?"Y":"N");
            measureItem.setContractcode(measureItemBO.getContractCode());
            measureItem.setIsnewdata(measureItemBO.getIsNewData());
            measureItem.setFcrate(measureItemBO.getFcRate());
            measureItem.setQtjxrate(measureItemBO.getQTjxRate());
            measureItem.setGlrate(measureItemBO.getGlRate());
            measureItem.setLrrate(measureItemBO.getLrRate());
            measureItem.setCategoryid(measureItemBO.getCategoryID());
            measureItem.setCbtotal(measureItemBO.getCBTotal());
            measureItem.setOriginalunit(measureItemBO.getOriginalUnit());
            measureItem.setProId(proId);
            measureItem.setStagetype(type);
            measureItemList.add(measureItem);
        }
        measureitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(measureItemList)) {
            measureitemMapper.insertBatchSomeColumn(measureItemList);
        }

        strSql = "select hz.* from Resource hz";
        List<EcoResourceBO> ecoResourceBOList = sqliteUtil.selectListRecord(EcoResourceBO.class, strSql);
        List<EcoResource> ecoResourceList =new ArrayList<>();
        for (EcoResourceBO ecoResourceBO : ecoResourceBOList) {
            EcoResource ecoResource = new EcoResource();
            ecoResource.setResourceid(ecoResourceBO.getID());
            ecoResource.setCosttypeid(ecoResourceBO.getCostTypeID());
            ecoResource.setCode(ecoResourceBO.getCode());
            ecoResource.setDescription(ecoResourceBO.getDescription());
            ecoResource.setSpec(ecoResourceBO.getSpec());
            ecoResource.setUnit(ecoResourceBO.getUnit());
            ecoResource.setBudgetrate(ecoResourceBO.getBudgetRate());
            ecoResource.setMarketrate(ecoResourceBO.getMarketRate());
            ecoResource.setQuantity(ecoResourceBO.getQuantity());
            ecoResource.setOriginate(ecoResourceBO.getOriginate());
            ecoResource.setSupplier(ecoResourceBO.getSupplier());
            ecoResource.setZcflag(ecoResourceBO.getZCFlag()?"Y":"N");
            ecoResource.setIsprovisional(ecoResourceBO.getIsProvisional()?"Y":"N");
            ecoResource.setBidnodeid(ecoResourceBO.getBidNodeID());
            ecoResource.setDwbidnodeid(ecoResourceBO.getDwBidNodeID());
            ecoResource.setProId(proId);
            ecoResource.setStagetype(type);
            ecoResourceList.add(ecoResource);
        }
        resourceMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(ecoResourceList)) {
            resourceMapper.insertBatchSomeColumn(ecoResourceList);
        }

        strSql = "select hz.* from OtherItem hz";
        List<OtherItemBo> otherItemBos = sqliteUtil.selectListRecord(OtherItemBo.class, strSql);
        List<EcoOtheritem> otherItems = new ArrayList<>();
        for (OtherItemBo oib : otherItemBos) {
            EcoOtheritem oi = new EcoOtheritem();
            oi.setOid(oib.getID());
            oi.setOpid(oib.getPID());
            oi.setOrdcode(oib.getOrdCode());
            oi.setName(oib.getName());
            oi.setUnit(oib.getUnit());
            oi.setQuantity(oib.getQuantity());
            oi.setCalcbase(oib.getCalcBase());
            oi.setCalctotal(oib.getCalcTotal());
            oi.setRate(oib.getRate());
            oi.setTotal(oib.getTotal());
            oi.setKind(oib.getKind());
            oi.setBidnodeid(oib.getBidNodeID());
            oi.setContractcode(oib.getContractCode());
            oi.setIsnewdata(oib.getIsNewData());
            oi.setCbtotal(oib.getCBTotal());
            oi.setOriginalunit(oib.getOriginalUnit());
            oi.setIslssc(oib.getLsSc() + "");
            oi.setItemtype(oib.getItemType());
            oi.setWbscategory(oib.getWBSCategory());
            oi.setStagetype(type);
            oi.setProId(proId);
            otherItems.add(oi);
        }
        otheritemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(otherItems)) {
            otheritemMapper.insertBatchSomeColumn(otherItems);
        }

        strSql = "select hz.* from CBZBitem hz";
        List<CbzbItemBO> cbzbItemBOList = sqliteUtil.selectListRecord(CbzbItemBO.class, strSql);
        String zzj = "";//总造价
        String zmj = "";//总面积
        //CBZBitem入库
        List<EcoCbzbitem> cbzbItemList =new ArrayList<>();
        for (CbzbItemBO cbzbItemBO : cbzbItemBOList) {
            EcoCbzbitem cbzbItem = new EcoCbzbitem();
            cbzbItem.setCbzbitemid(cbzbItemBO.getID());
            cbzbItem.setCbzbitempid(cbzbItemBO.getPID());
            cbzbItem.setName(cbzbItemBO.getName());
            cbzbItem.setEigenvalues(cbzbItemBO.getEigenvalues());
            cbzbItem.setIsrequired(cbzbItemBO.getIsRequired());
            cbzbItem.setDatatype(cbzbItemBO.getDataType());
            cbzbItem.setBidnodeid(cbzbItemBO.getBidNodeId());
            cbzbItem.setIsdefault(cbzbItemBO.getIsDefault());
            cbzbItem.setIsfeature(cbzbItemBO.getIsFeature());
            cbzbItem.setFeatureid(cbzbItemBO.getFeatureID());
            cbzbItem.setType(cbzbItemBO.getType());
            cbzbItem.setSelectCode(cbzbItemBO.getSELECT_CODE());
            cbzbItem.setSelectLabel(cbzbItemBO.getSELECT_LABEL());
            cbzbItem.setSelectCodeValue(cbzbItemBO.getSELECT_CODE_Value());
            cbzbItem.setCalculateCaliberType(cbzbItemBO.getCALCULATE_CALIBER_TYPE());
            cbzbItem.setIssum(cbzbItemBO.getIsSum()?"Y":"N");
            cbzbItem.setProId(proId);
            cbzbItem.setStagetype(type);
            cbzbItemList.add(cbzbItem);
            if (StringUtil.equals(cbzbItemBO.getName(),"单位工程总造价")){
                zzj = cbzbItemBO.getEigenvalues();
            }else if (StringUtil.equals(cbzbItemBO.getName(),"道路面积(m2)")){
                zmj = cbzbItemBO.getEigenvalues();
            }
        }
        cbzbitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(cbzbItemList)) {
            cbzbitemMapper.insertBatchSomeColumn(cbzbItemList);
        }

        strSql = "select cf.* from CbFeeItemZBInfo cf";
        List<CbFeeItemZBInfoBO> cbFeeItemZBInfoBOs = sqliteUtil.selectListRecord(CbFeeItemZBInfoBO.class, strSql);
        List<EcoCbfeeitemzbinfo> CbFeeItemZBInfos =new ArrayList<>();
        for (CbFeeItemZBInfoBO cbFeeItemZBInfoBO : cbFeeItemZBInfoBOs) {
            EcoCbfeeitemzbinfo cbFeeItemZBInfo = new EcoCbfeeitemzbinfo();
            cbFeeItemZBInfo.setCbfeeitemzbinfoid(cbFeeItemZBInfoBO.getID());
            cbFeeItemZBInfo.setCbfeeitemid(cbFeeItemZBInfoBO.getCbFeeItemID());
            cbFeeItemZBInfo.setReltype(cbFeeItemZBInfoBO.getRelType());
            cbFeeItemZBInfo.setStructid(cbFeeItemZBInfoBO.getStructID());
            cbFeeItemZBInfo.setItemid(cbFeeItemZBInfoBO.getItemID());
            cbFeeItemZBInfo.setItemname(cbFeeItemZBInfoBO.getItemName());
            cbFeeItemZBInfo.setBidnodeid(cbFeeItemZBInfoBO.getBidNodeID());
            cbFeeItemZBInfo.setGclxs(Convert.toBigDecimal(cbFeeItemZBInfoBO.getGclxs()));
            cbFeeItemZBInfo.setJsquantity(Convert.toBigDecimal(cbFeeItemZBInfoBO.getJsQuantity()));
            cbFeeItemZBInfo.setProId(proId);
            cbFeeItemZBInfo.setStagetype(type);
            CbFeeItemZBInfos.add(cbFeeItemZBInfo);
        }
        cbfeeitemzbinfoMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(CbFeeItemZBInfos)) {
            cbfeeitemzbinfoMapper.insertBatchSomeColumn(CbFeeItemZBInfos);
        }

        strSql = "select cf.* from CbFeeItem cf";
        List<CbFeeItemNew> CbFeeItemNews = sqliteUtil.selectListRecord(CbFeeItemNew.class, strSql);
        List<EcoCbfeeitem> cbFeeItems =new ArrayList<>();
        for (CbFeeItemNew cbFeeItemNew : CbFeeItemNews) {
            EcoCbfeeitem cbFeeItem = new EcoCbfeeitem();
            cbFeeItem.setCbfeeitemid(cbFeeItemNew.getID());
            cbFeeItem.setPid(cbFeeItemNew.getPID());
            cbFeeItem.setOrgincode(cbFeeItemNew.getOrginCode());
            cbFeeItem.setCode(cbFeeItemNew.getCode());
            cbFeeItem.setName(cbFeeItemNew.getName());
            cbFeeItem.setSpec(cbFeeItemNew.getSpec());
            cbFeeItem.setUnit(cbFeeItemNew.getUnit());
            cbFeeItem.setYsamount(cbFeeItemNew.getYsAmount());
            cbFeeItem.setYsprice(cbFeeItemNew.getYsPrice());
            BigDecimal ysTotal = cbFeeItemNew.getYsTotal();
            cbFeeItem.setYstotal(ysTotal);
            BigDecimal targetNoTaxTotal = cbFeeItemNew.getTargetNoTaxTotal();
            cbFeeItem.setTargetnotaxtotal(targetNoTaxTotal);
            // 计算 盈亏额(不含税) 和 盈亏率(不含税)
            // 盈亏额不含税= 收入-不含税合计
            BigDecimal notaxyke = NumberUtil.subtractNew(ysTotal,targetNoTaxTotal);
            cbFeeItem.setNotaxyke(notaxyke);
            // 盈亏率 = (收入-不含税合计) / 收入
            BigDecimal notaxykl = NumberUtil.divideNew(notaxyke,4, ysTotal);
            BigDecimal targetTaxTotal = cbFeeItemNew.getTargetTaxTotal();
            cbFeeItem.setTargettaxtotal(targetTaxTotal);
            // 计算 盈亏额(含税) 和 盈亏率(含税)
            // 盈亏额含税= 收入-含税合计
            BigDecimal taxyke = NumberUtil.subtractNew(ysTotal, targetTaxTotal);
            cbFeeItem.setTaxyke(taxyke);
            // 盈亏率 = (收入-含税合计) / 收入
            BigDecimal taxykl = NumberUtil.divideNew(taxyke,4, ysTotal);
            cbFeeItem.setTaxykl(taxykl);
            cbFeeItem.setNotaxykl(notaxykl);
            cbFeeItem.setTargetamout(cbFeeItemNew.getTargetAmout());
            cbFeeItem.setAmountratio(cbFeeItemNew.getAmountRatio());
            cbFeeItem.setTargetamountexp(cbFeeItemNew.getTargetAmountExp());
            cbFeeItem.setTargetnotaxprice(cbFeeItemNew.getTargetNoTaxPrice());
            cbFeeItem.setTargettaxprice(cbFeeItemNew.getTargetTaxPrice());
            cbFeeItem.setTargetzzsl(cbFeeItemNew.getTargetZzsl());
            cbFeeItem.setTargetsj(cbFeeItemNew.getTargetSj());
            cbFeeItem.setTargetsjtotal(cbFeeItemNew.getTargetSjTotal());
            cbFeeItem.setDatatype(cbFeeItemNew.getDataType());
            cbFeeItem.setFeetype(cbFeeItemNew.getFeeType());
            cbFeeItem.setZysj(cbFeeItemNew.getZysj());
            cbFeeItem.setGq(cbFeeItemNew.getGq());
            cbFeeItem.setFbxs(cbFeeItemNew.getFbxs());
            cbFeeItem.setBidnodeid(cbFeeItemNew.getBidNodeID());
            cbFeeItem.setTemplid(cbFeeItemNew.getTemplId());
            cbFeeItem.setRemark(cbFeeItemNew.getRemark());
            cbFeeItem.setSfdk(cbFeeItemNew.getSfdk()?"Y":"N");
            cbFeeItem.setOverhead(cbFeeItemNew.getOverhead());
            cbFeeItem.setProfit(cbFeeItemNew.getProfit());
            cbFeeItem.setTargettxl(cbFeeItemNew.getTargetTxl());
            cbFeeItem.setPx(cbFeeItemNew.getPX());
            cbFeeItem.setFbms(cbFeeItemNew.getFbms());
            cbFeeItem.setBackcolor(cbFeeItemNew.getBackColor());
            cbFeeItem.setFeeitemclass(cbFeeItemNew.getFeeItemClass());
            cbFeeItem.setCategoryids(cbFeeItemNew.getCategoryIDs());
            cbFeeItem.setIsmix(cbFeeItemNew.getIsMix()?"Y":"N");
            cbFeeItem.setIssystem(cbFeeItemNew.getIsSystem()?"Y":"N");
            cbFeeItem.setIsgs(cbFeeItemNew.getIsGs()?"Y":"N");
            cbFeeItem.setCoefficient(cbFeeItemNew.getCoefficient());
            cbFeeItem.setSchemecontent(cbFeeItemNew.getSchemeContent());
            cbFeeItem.setClmatchstring(cbFeeItemNew.getCLMatchString());
            cbFeeItem.setCldematchstring(cbFeeItemNew.getCLDeMatchString());
            cbFeeItem.setSfbhglflr(cbFeeItemNew.getSfBhGlfLr()?"Y":"N");
            cbFeeItem.setMergefeeids(cbFeeItemNew.getMergeFeeIDs());
            cbFeeItem.setIsmergefee(cbFeeItemNew.getIsMergeFee()?"Y":"N");
            cbFeeItem.setCltype(cbFeeItemNew.getCLType());
            cbFeeItem.setVisible(cbFeeItemNew.getVisible()?"Y":"N");
            cbFeeItem.setIsfc(cbFeeItemNew.getIsFc()?"Y":"N");
            cbFeeItem.setUseqdl(cbFeeItemNew.getUseQdl()?"Y":"N");
            cbFeeItem.setItemcontent(cbFeeItemNew.getItemContent());
            cbFeeItem.setDksjtotal(cbFeeItemNew.getDksjTotal());
            cbFeeItem.setSfgf(cbFeeItemNew.getSfGF()?"Y":"N");
            cbFeeItem.setSfzj(cbFeeItemNew.getSfZj()?"Y":"N");
            cbFeeItem.setIsyssr(cbFeeItemNew.getIsYsSr()?"Y":"N");
            cbFeeItem.setSflwqb(cbFeeItemNew.getSfLwqb()?"Y":"N");
            cbFeeItem.setCbkm(cbFeeItemNew.getCbkm());
            cbFeeItem.setRgfxfl(cbFeeItemNew.getRgfXfl());
            cbFeeItem.setFcfxfl(cbFeeItemNew.getFcfXfl());
            cbFeeItem.setXxjjfxfl(cbFeeItemNew.getXxjjfXfl());
            cbFeeItem.setIsyscbprice(cbFeeItemNew.getIsYsCbPrice()?"Y":"N");
            cbFeeItem.setIsnewdata(cbFeeItemNew.getIsNewData()?"Y":"N");
            cbFeeItem.setWlbm(cbFeeItemNew.getWlbm());
            cbFeeItem.setCalcrule(cbFeeItemNew.getCalcRule());
            cbFeeItem.setOriginalunit(cbFeeItemNew.getOriginalUnit());
            cbFeeItem.setZunit(cbFeeItemNew.getZUnit());
            cbFeeItem.setDwunit(cbFeeItemNew.getDwUnit());
            cbFeeItem.setContent(cbFeeItemNew.getContent());
            cbFeeItem.setResponsibilityid(cbFeeItemNew.getResponsibilityID());
            cbFeeItem.setIszg(cbFeeItemNew.getIsZg()!=null?cbFeeItemNew.getIsZg()?"1":"0":null);
            cbFeeItem.setProId(proId);
            cbFeeItem.setCostcategoryid(cbFeeItemNew.getCostCategoryId());
            cbFeeItem.setContractcategoryid(cbFeeItemNew.getContractCategoryID());
            cbFeeItem.setQyfl(cbFeeItemNew.getQyfl());
            cbFeeItem.setStagetype(type);
            cbFeeItems.add(cbFeeItem);
        }
        cbfeeitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(cbFeeItems)) {
            cbfeeitemMapper.insertBatchSomeColumn(cbFeeItems);
        }

        strSql = "select ps.* from ProjectSgjx ps";
        List<ProjectSgjxBO> projectSgjxBOs = sqliteUtil.selectListRecord(ProjectSgjxBO.class, strSql);
        List<EcoProjectsgjx> projectSgjxs =new ArrayList<>();
        for (ProjectSgjxBO projectSgjxBO : projectSgjxBOs) {
            EcoProjectsgjx projectsgjx = new EcoProjectsgjx();
            projectsgjx.setOldid(projectSgjxBO.getID());
            projectsgjx.setName(projectSgjxBO.getName());
            projectsgjx.setDatatype(projectSgjxBO.getDataType());
            projectsgjx.setBidnodeid(projectSgjxBO.getBidNodeID());
            projectsgjx.setPid(projectSgjxBO.getPID());
            projectsgjx.setAmount(projectSgjxBO.getAmount());
            projectsgjx.setSpec(projectSgjxBO.getSpec());
            projectsgjx.setStartdate(projectSgjxBO.getStartDate());
            projectsgjx.setEnddate(projectSgjxBO.getEndDate());
            projectsgjx.setIntervalmonth(projectSgjxBO.getIntervalMonth());
            projectsgjx.setSp(projectSgjxBO.getSp());
            projectsgjx.setProId(proId);
            projectsgjx.setStagetype(type);
            projectSgjxs.add(projectsgjx);
        }
        projectsgjxMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(projectSgjxs)) {
            projectsgjxMapper.insertBatchSomeColumn(projectSgjxs);
        }

        strSql = "select ca.* from CostAnalysis ca";
        List<CostAnalysisBO> costAnalysisBOs = sqliteUtil.selectListRecord(CostAnalysisBO.class, strSql);
        List<EcoCostanalysis> costAnalysiss =new ArrayList<>();
        for (CostAnalysisBO costAnalysisBO : costAnalysisBOs) {
            EcoCostanalysis costAnalysis = new EcoCostanalysis();
            costAnalysis.setOldid(costAnalysisBO.getID());
            costAnalysis.setOldpid(Convert.toStr(costAnalysisBO.getPID()));
            costAnalysis.setXmfy(costAnalysisBO.getXmfy());
            costAnalysis.setBhshtsr(costAnalysisBO.getBhshtsr());
            costAnalysis.setXxssl(costAnalysisBO.getXxssl());
            costAnalysis.setGlffl(costAnalysisBO.getGlffl());
            costAnalysis.setKdkjxssl(costAnalysisBO.getKdkjxssl());
            costAnalysis.setFjssl(costAnalysisBO.getFjssl());
            costAnalysis.setHszj(costAnalysisBO.getHszj());
            costAnalysis.setFylx(costAnalysisBO.getFylx());
            costAnalysis.setXxs(costAnalysisBO.getXxs());
            costAnalysis.setHshtsr(costAnalysisBO.getHshtsr());
            costAnalysis.setSjzffb(costAnalysisBO.getSjzffb());
            costAnalysis.setKdkjxs(costAnalysisBO.getKdkjxs());
            costAnalysis.setZzs(costAnalysisBO.getZzs());
            costAnalysis.setFjs(costAnalysisBO.getFjs());
            costAnalysis.setBhscbhj(costAnalysisBO.getBhscbhj());
            costAnalysis.setHscbhj(costAnalysisBO.getHscbhj());
            costAnalysis.setBhsyke(costAnalysisBO.getBhsyke());
            costAnalysis.setHsyke(costAnalysisBO.getHsyke());
            costAnalysis.setBhsykl(costAnalysisBO.getBhsykl());
            costAnalysis.setHsykl(costAnalysisBO.getHsykl());
            costAnalysis.setProId(proId);
            costAnalysis.setStagetype(type);
            costAnalysiss.add(costAnalysis);
        }
        ecoCostanalysisMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(costAnalysiss)) {
            ecoCostanalysisMapper.insertBatchSomeColumn(costAnalysiss);
        }
        strSql = "select ci.* from CbInfo ci";
        List<CbInfoBO> cbInfoBOs = sqliteUtil.selectListRecord(CbInfoBO.class, strSql);
        List<EcoCbinfo> cBInfos =new ArrayList<>();
        for (CbInfoBO cbInfoBO : cbInfoBOs) {
            EcoCbinfo cBInfo = new EcoCbinfo();
            cBInfo.setOldid(cbInfoBO.getID());
            cBInfo.setName(cbInfoBO.getName());
            cBInfo.setContent(cbInfoBO.getContent());
            cBInfo.setBidnodeid(cbInfoBO.getBidNodeID());
            cBInfo.setIdx(cbInfoBO.getIdx());
            cBInfo.setDatatype(cbInfoBO.getDataType());
            cBInfo.setMemo(cbInfoBO.getMemo());
            cBInfo.setType(cbInfoBO.getType());
            cBInfo.setSelecTlabel(cbInfoBO.getSELECT_LABEL());
            cBInfo.setProId(proId);
            cBInfo.setStagetype(type);
            cBInfos.add(cBInfo);
        }
        cbinfoMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(cBInfos)) {
            cbinfoMapper.insertBatchSomeColumn(cBInfos);
        }

        strSql = "select hz.* from LMMDetail hz";
        List<LMMDetailBO> lMMDetailBOList = sqliteUtil.selectListRecord(LMMDetailBO.class, strSql);
        List<EcoLmmdetail> lMMDetailList =new ArrayList<>();
        for (LMMDetailBO lMMDetailBO : lMMDetailBOList) {
            EcoLmmdetail lMMDetail = new EcoLmmdetail();
            lMMDetail.setBqitemid(lMMDetailBO.getBQItemID());
            lMMDetail.setLmmdetailid(lMMDetailBO.getID());
            lMMDetail.setQuantity(lMMDetailBO.getQuantity());
            lMMDetail.setResourceid(lMMDetailBO.getResourceID());
            lMMDetail.setReltype(lMMDetailBO.getRelType());
            lMMDetail.setFxflag(lMMDetailBO.getFXFlag());
            lMMDetail.setRelationid(lMMDetailBO.getRelationID());
            lMMDetail.setCbprice(lMMDetailBO.getCbPrice());
            lMMDetail.setProId(proId);
            lMMDetail.setStagetype(type);
            lMMDetailList.add(lMMDetail);
        }
        lmmdetailMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(lMMDetailList)) {
            lmmdetailMapper.insertBatchSomeColumn(lMMDetailList);
        }


        strSql = "select hz.* from Xmhz hz";
        List<XmhzBO> xmhzBOList = sqliteUtil.selectListRecord(XmhzBO.class, strSql);
        List<EcoXmhz> xmhzList =new ArrayList<>();
        for (XmhzBO xmhzBO :xmhzBOList) {
            strSql = "select hz.* from Xmhz hz where hz.ID ='"+xmhzBO.getPID()+"'";
            EcoXmhz xmhz = new EcoXmhz();
            xmhz.setHzid(xmhzBO.getID());
            try {
                XmhzBO selectOneRecord = sqliteUtil.selectOneRecord(XmhzBO.class, strSql);
                if(selectOneRecord==null){
                    xmhz.setHzpid(null);
                }else{
                    xmhz.setHzpid(xmhzBO.getPID());
                }
            } catch (Exception e) {
                xmhz.setHzpid(null);
            }
            xmhz.setName(xmhzBO.getName());
            xmhz.setYsamount(xmhzBO.getYsAmount());
            xmhz.setYszjzb(xmhzBO.getYsZjzb());
            xmhz.setJzmj(xmhzBO.getJzmj());
            xmhz.setPmzj(xmhzBO.getPmzj());
            xmhz.setTjysamount(xmhzBO.getTJYsAmount());
            xmhz.setAzysamount(xmhzBO.getAZYsAmount());
            xmhz.setSzysamount(xmhzBO.getSZYsAmount());
            xmhz.setTjpmzj(xmhzBO.getTJPmzj());
            xmhz.setAzpmzj(xmhzBO.getAZPmzj());
            xmhz.setSzpmzj(xmhzBO.getSZPmzj());
            xmhz.setDatatype(xmhzBO.getDataType());
            xmhz.setPx(xmhzBO.getPX());
            xmhz.setZjxj(xmhzBO.getZjxj());
            xmhz.setDwzjxj(xmhzBO.getDWZjxj());
            xmhz.setProId(proId);
            xmhz.setStagetype(type);
            xmhzList.add(xmhz);
        }
        xmhzMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(xmhzList)) {
           xmhzMapper.insertBatchSomeColumn(xmhzList);
        }

        strSql = "select hz.* from ContractInfo hz";
        List<ContractInfoBO> cContractInfoBOList = sqliteUtil.selectListRecord(ContractInfoBO.class, strSql);
        List<EcoContractinfo> contractInfoList =new ArrayList<>();
        for (ContractInfoBO contractInfoBO : cContractInfoBOList) {
            EcoContractinfo contractInfo = new EcoContractinfo();
            contractInfo.setOldid(	contractInfoBO.getID());
            contractInfo.setPid(	contractInfoBO.getPID());
            contractInfo.setCode(	contractInfoBO.getCode());
            contractInfo.setName(	contractInfoBO.getName());
            contractInfo.setSpec(	contractInfoBO.getSpec());
            contractInfo.setUnit(	contractInfoBO.getUnit());
            contractInfo.setHtamout(	contractInfoBO.getHtAmout());
            contractInfo.setHtnotaxprice(	contractInfoBO.getHtNoTaxPrice());
            contractInfo.setHtnotaxtotal(	contractInfoBO.getHtNoTaxTotal());
            contractInfo.setTargetamout(	contractInfoBO.getTargetAmout());
            contractInfo.setTargetnotaxprice(	contractInfoBO.getTargetNoTaxPrice());
            contractInfo.setTargetnotaxtotal(	contractInfoBO.getTargetNoTaxTotal());
            contractInfo.setJce(	contractInfoBO.getJce());
            contractInfo.setJcl(	contractInfoBO.getJcl());
            contractInfo.setContent(	contractInfoBO.getContent());
            contractInfo.setCalcrule(	contractInfoBO.getCalcRule());
            contractInfo.setMemo(	contractInfoBO.getMemo());
            contractInfo.setCosttype(	contractInfoBO.getCostType());
            contractInfo.setProId(proId);
            contractInfo.setZysj(contractInfoBO.getZysj());
            contractInfo.setTargettxl(contractInfoBO.getTargetTxl());
            contractInfo.setStagetype(type);
            contractInfoList.add(contractInfo);
        }
        contractinfoMapper.deleteByProIdAndStagetype(proId,type);
       if (CollUtil.isNotEmpty(contractInfoList)) {
           contractinfoMapper.insertBatchSomeColumn(contractInfoList);
       }

        strSql = "select hz.* from CBTabInfo hz";
        List<CbTabInfoBO> cbTabInfoBOList = sqliteUtil.selectListRecord(CbTabInfoBO.class, strSql);
        List<EcoCbtabinfo> cbTabInfoList =new ArrayList<>();
        for (CbTabInfoBO cbTabInfoBO : cbTabInfoBOList) {
            EcoCbtabinfo cbTabInfo = new EcoCbtabinfo();
            cbTabInfo.setTabinfoid(cbTabInfoBO.getID());
            cbTabInfo.setDescription(cbTabInfoBO.getDescription());
            cbTabInfo.setFeetype(cbTabInfoBO.getFeeType());
            cbTabInfo.setBidnodeid(cbTabInfoBO.getBidNodeID());
            cbTabInfo.setProId(proId);
            cbTabInfo.setStagetype(type);
            cbTabInfoList.add(cbTabInfo);
        }
        cbtabinfoMapper.deleteByProIdAndStagetype(proId,type);
       if (CollUtil.isNotEmpty(cbTabInfoList)) {
           cbtabinfoMapper.insertBatchSomeColumn(cbTabInfoList);
       }

        String secondarySql = "SELECT * FROM SecondaryEfficiency";
        List<SecondaryBo> secondaryBos = sqliteUtil.selectListRecord(SecondaryBo.class, secondarySql);
        List<EcoSecondary> secondaryList = new ArrayList<>();
        for (SecondaryBo bo : secondaryBos) {
            EcoSecondary secondary = new EcoSecondary();
            secondary.setOid(bo.getID());
            secondary.setXmfy(bo.getXmfy());
            secondary.setHtsr(bo.getHtsr());
            secondary.setMbcb(bo.getMbcb());
            secondary.setYke(bo.getYke());
            secondary.setYkl(bo.getYkl());
            secondary.setProId(proId);
            secondary.setStagetype(type);
            secondaryList.add(secondary);
        }
        secondaryMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(secondaryList)) {
           secondaryMapper.insertBatchSomeColumn(secondaryList);
        }

        String bqItemMateSql = "SELECT * FROM BQItemMate";
        List<BQItemMateBo> bqItemMateBos = sqliteUtil.selectListRecord(BQItemMateBo.class, bqItemMateSql);
        List<EcoBqitemmate> bqItemMateList = new ArrayList<>();
        for (BQItemMateBo bo : bqItemMateBos) {
            EcoBqitemmate convert = BQItemMateBo.convert(bo, proId);
            convert.setStagetype(type);
            bqItemMateList.add(convert);
        }
        bqitemmateMapper.deleteByProIdAndStagetype(proId,type);
       if (CollUtil.isNotEmpty(bqItemMateList)) {
           bqitemmateMapper.insertBatchSomeColumn(bqItemMateList);
       }


        String cbSummaryZylrlSql = "SELECT * FROM CbSummaryZylrl";
        List<CbSummaryZylrlBo> summaryZylrlBos = sqliteUtil.selectListRecord(CbSummaryZylrlBo.class, cbSummaryZylrlSql);
        List<EcoCbsummaryzylrl> cbsummaryZylrlList = new ArrayList<>();
        for (CbSummaryZylrlBo bo : summaryZylrlBos) {
            EcoCbsummaryzylrl convert = CbSummaryZylrlBo.convert(bo);
            convert.setStagetype(type);
            convert.setProId(proId);
            cbsummaryZylrlList.add(convert);
        }
        cbsummaryzylrlMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(cbsummaryZylrlList)) {
            cbsummaryzylrlMapper.insertBatchSomeColumn(cbsummaryZylrlList);
        }


        strCbSql = "select * from CbSummary";
        List<CbSummary> cbSummaryList = sqliteUtil.selectListRecord(CbSummary.class, strCbSql);
        List<EcoCbsummary> cbsummaries = new ArrayList<>();
        for (CbSummary summary : cbSummaryList) {
            EcoCbsummary one=new EcoCbsummary();
            one.setOid(summary.getID());
            one.setPid(summary.getPID());
            one.setCode(summary.getCode());
            one.setName(summary.getName());
            one.setOrdcode(summary.getOrdCode());
            one.setBidnodeid(summary.getBidNodeID());
            one.setXh(summary.getXH());
            one.setUnit(summary.getUnit());
            one.setYstotal(summary.getYsTotal());
            one.setSrzb(summary.getSrzb());
            one.setTargettotal(summary.getTargetTotal());
            one.setTargetnottotal(summary.getTargetNoTotal());
            one.setCbzbnottax(summary.getCbzbNoTax());
            one.setJyenottax(summary.getJyeNoTax());
            one.setJylnottax(summary.getJylNoTax());
            one.setRemark(summary.getRemark());
            one.setStagetype(type);
            one.setProId(proId);
            one.setSrpmzj(summary.getSrpmzj());
            one.setTargetcbpmzj(summary.getTargetCbpmzj());
            cbsummaries.add(one);
        }

        cbsummaryMapper.deleteByProIdAndStagetype(proId,type);
       if (CollUtil.isNotEmpty(cbsummaries)) {
           cbsummaryMapper.insertBatchSomeColumn(cbsummaries);
       }


        String strCostUploadSql = "select * from CostUpload";
        List<CostUploadBo> costUploadBos = sqliteUtil.selectListRecord(CostUploadBo.class, strCostUploadSql);
        List<EcoCostupload> costUploadList = new ArrayList<>();
        for (CostUploadBo cbo : costUploadBos) {
            EcoCostupload costUpload = new EcoCostupload();
            costUpload.setOld(cbo.getID());
            costUpload.setPcname(cbo.getPcName());
            costUpload.setPcstatue(cbo.getPcStatue());
            costUpload.setUploadversion(cbo.getUploadVersion());
            costUpload.setLastuploadtime(cbo.getLastUploadTime());
            costUpload.setFromid(cbo.getFromID());
            costUpload.setFromcode(cbo.getFromCode());
            costUpload.setFromname(cbo.getFromName());
            costUpload.setBidnodeids(cbo.getBidNodeIDs());
            costUpload.setUploadedbidnodeids(cbo.getUploadedBidNodeIDs());
            costUpload.setProId(proId);
            costUpload.setStagetype(type);
            costUploadList.add(costUpload);
        }
        costuploadMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(costUploadList)) {
           costuploadMapper.insertBatchSomeColumn(costUploadList);
        }
    }

    @Transactional
    public RestBodyResponse uploadYdCostSqliteFile(String proID, InputStream inputStream,String costType,String fileName){
        String costTemplateUploadPath = sqliteUpPathConfig.getCcbpath();
        Date uploadDate = new Date();
        File newFile = new File(costTemplateUploadPath,"CostTempl_" + DateFormatUtils.format(uploadDate, "yyyyMMddHHmmssSSS"));
        try {
            FileUtils.copyInputStreamToFile(inputStream, newFile);
        } catch (IOException e) {
            e.printStackTrace();
            return RestBodyResponse.fail("上传失败!",e.getMessage());
        }
        if ( newFile.length() < 1 ) {
            // 文件里啥都没有
            return RestBodyResponse.fail("上传失败!","文件为空");
        }
        // 项目附件
        ProjectInfoAttachment attachment = new ProjectInfoAttachment();
        attachment.setProjectId(proID);
        attachment.setAttachmentName(fileName);
        attachment.setAttachmentType(costType);
        attachment.setUploadTime(uploadDate);
        attachment.setLocalFilePath(costTemplateUploadPath+"/"+ "CostTempl_" +DateFormatUtils.format(uploadDate, "yyyyMMddHHmmssSSS"));
        projectInfoAttachmentMapper.insert(attachment);

        String zipTempDirPath = costTemplateUploadPath +"/"+ UUID.randomUUID().toString();
        SqliteUtil sqliteUtil = new SqliteUtil();
        try {
            ZipUtil.decompressZip(newFile, zipTempDirPath);
            File newydFile = new File(zipTempDirPath,"CostFile");
            // 绝对路径
            String absolutePath = newydFile.getAbsolutePath();
            sqliteUtil.getConnection(absolutePath);

            String downFileName = "CostTempl_" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS")+"_"+proID + ".ycb";
            // 本地资源路径
            String localPath = RuoYiConfig.getProfile();
            File downFile = new File(localPath,downFileName);
            try {
                FileUtils.copyFile(newFile, downFile);
            } catch (IOException e) {
                return RestBodyResponse.fail("上传失败!","解压缩zip文件出错。");
            }
            LibProject project = libProjectMapper.selectById(proID);
            parseYcbDataToBd(sqliteUtil,project,costType,downFile);
            if(CCBConstants.CCB_TYPE.MBZRCB.getCode().equals(costType)){
                //YCB覆盖CCB的数据
                parseCbbDataToBd(sqliteUtil,project,costType);
                //02类型 关联目标责任成本 和 开工预算  所以给开工预算也保存数据(本可以删除KGYSSJ枚举，但其他地方有使用)
                parseCbbDataToBd(sqliteUtil,project,CCBConstants.CCB_TYPE.KGYSSJ.getCode());
                parseYcbDataToBd(sqliteUtil,project,CCBConstants.CCB_TYPE.KGYSSJ.getCode(),downFile);
            }
            if(CCBConstants.CCB_TYPE.JGCBFX.getCode().equals(costType)){
                //04类型关联竣工成本分析和竣工结算  可以传ccb 所以给竣工结算也保存数据(本可以删除JGJSSJ枚举，但其他地方有使用)
                parseYcbDataToBd(sqliteUtil,project,CCBConstants.CCB_TYPE.JGJSSJ.getCode(),downFile);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return RestBodyResponse.fail("上传失败!","解压缩zip文件出错。");
        } finally {
            sqliteUtil.relase();
            // 删除临时目录和临时zip文件
            try {
                FileUtils.deleteDirectory(new File(zipTempDirPath));
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }

        return RestBodyResponse.ok("上传成功!","","");
    }

    @Autowired
    private YdZbstructitemMapper ydZbstructitemMapper;
    @Autowired
    private YdTimeMapper ydTimeMapper;
    @Autowired
    private CostAnalysisReportMapper costAnalysisReportMapper;
    @Autowired
    private YdCbfeeiteminfoMapper ydCbfeeiteminfoMapper;
    @Autowired
    private CostAnalysisHzMapper costAnalysisHzMapper;
    @Autowired
    private YdCostanalysisListMapper ydCostanalysisListMapper;
    @Autowired
    private DataToolFileversionMapper dataToolFileversionMapper;
    @Autowired
    private YdModifyitemMapper ydModifyitemMapper;
    @Autowired
    private YdCbfeeitemMapper ydCbfeeitemMapper;
    @Autowired
    private YdCbsummaryMapper ydCbsummaryMapper;
    @Autowired
    private YdCostanalysisMapper ydCostanalysisMapper;
    @Autowired
    private YdCbfeeiteminfoStandardMapper ydCbfeeiteminfoStandardMapper;
    @Autowired
    private YdBqitemMateMapper ydBqitemMateMapper;
    @Autowired
    private YdSummaryMapper ydSummaryMapper;
    @Autowired
    private YdcbFeeitemMateMapper ydcbFeeitemMateMapper;
    @Autowired
    private EcoCbhzinfoMapper ecoCbhzinfoMapper;
    @Autowired
    private YdczSummaryMapper ydczSummaryMapper;



    public void parseYcbDataToBd(SqliteUtil sqliteUtil, LibProject project, String costType,File downFile) {
        String proId = project.getId();
        // YdZbstructitem
        String ydzbStructSql = "select * from YDZBStructItem";
        List<YDZBStructItemBo> ydzbStructItemBos = sqliteUtil.selectListRecord(YDZBStructItemBo.class, ydzbStructSql);
        // 转化成YdZbstructitem
        List<YdZbstructitem> ydZbstructItems = new ArrayList<>();
        for (YDZBStructItemBo bo : ydzbStructItemBos) {
            YdZbstructitem item = new YdZbstructitem();
//            item.setId(UUID.randomUUID().toString().replace("-", ""));
            item.setOld(bo.getID());
            item.setPid(bo.getPID());
            item.setName(bo.getName());
            item.setUnit(bo.getUnit());
            item.setJskj(bo.getJskj());
            item.setJskjz(bo.getJskjz());
            item.setDwzj(bo.getDwzj());
            item.setZb(bo.getZb());

            item.setCoefficient(bo.getCoefficient());
            item.setCoefficientcb(bo.getCoefficientCB());
            item.setStructid(bo.getStructID());
            item.setBidnodeid(bo.getBidNodeID());

            item.setYstotal(bo.getYsTotal());
            item.setCbtotal(bo.getCbTotal());
            item.setYsquantity(bo.getYsQuantity());
            item.setCbquantity(bo.getCbQuantity());
            item.setDatatype(bo.getDataType());
            item.setDwcb(bo.getDwcb());

            item.setKeyid(bo.getKeyID());
            item.setReltype(bo.getRelType());
            item.setStructname(bo.getStructName());
            item.setShowtype(bo.getShowType());
            item.setJzgcdwzj(bo.getJZGCDwzj());
            item.setJzgczb(bo.getJZGCZb());


            item.setZsgcdwzj(bo.getZSGCDwzj());
            item.setZsgczb(bo.getZSGCZb());
            item.setAzgcdwzj(bo.getAZGCDwzj());
            item.setAzgczb(bo.getAZGCZb());
            item.setSzgcdwzj(bo.getSZGCDwzj());
            item.setSzgczb(bo.getSZGCZb());

            item.setJzgcystotal(bo.getJZGCYsTotal());
            item.setZsgcystotal(bo.getZSGCYsTotal());
            item.setAzgcystotal(bo.getAZGCYsTotal());
            item.setSzgcystotal(bo.getSZGCYsTotal());
            item.setAmount(bo.getAmount());
            item.setJzgcdj(bo.getJZGCDj());


            item.setAzgcdj(bo.getAZGCDj());
            item.setSzgcdj(bo.getSZGCDj());
            item.setZsgcdj(bo.getZSGCDj());
            item.setType(bo.getType());
            item.setFbnames(bo.getFbNames());

            item.setAzgccoefficient(bo.getAZGCCoefficient());
            item.setJzgccoefficient(bo.getJZGCCoefficient());
            item.setSzgccoefficient(bo.getSZGCCoefficient());
            item.setZsgccoefficient(bo.getZSGCCoefficient());
            item.setJzgcquantity(bo.getJZGCQuantity());
            item.setAzgcquantity(bo.getAZGCQuantity());
            item.setSzgcquantity(bo.getSZGCQuantity());
            item.setZsgcquantity(bo.getZSGCQuantity());

            item.setIszbxy2(bo.isZBXY2());

            item.setProId(proId);
            item.setStagetype(costType);
            ydZbstructItems.add(item);
        }
        ydZbstructitemMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydZbstructItems)){
            ydZbstructitemMapper.insertBatchSomeColumn(ydZbstructItems);
        }

        // YDTime
        String ydTimeSql = "select * from YDTime";
        List<YDTimeBo> ydTimeBos = sqliteUtil.selectListRecord(YDTimeBo.class, ydTimeSql);
        List<YdTime> ydTimes = new ArrayList<>();
        List<CostAnalysisReport> costAnalysisReports = new ArrayList<>();
        for (YDTimeBo bo : ydTimeBos) {
            YdTime item = new YdTime();
            CostAnalysisReport costAnalysisReport = new CostAnalysisReport();
//            item.setId(UUID.randomUUID().toString().replace("-", ""));
            item.setOid(bo.getID());
            item.setStartdate(bo.getStartDate());
            item.setEnddate(bo.getEndDate());
            item.setName(bo.getName());
            item.setHasczwj(bo.getHasCzwj() + "");
            item.setGdblsb(bo.getGdblSB());
            item.setIsYsc(bo.getIsYsc());
            item.setIsGdblsb(bo.getIsGdblSB());
            item.setIsFbfxsb(bo.getIsFbfxSB());
            item.setMonthUnRealCb(bo.getMonthUnRealCb());
            item.setMonthRealCb(bo.getMonthRealCb());
            item.setProId(proId);
            item.setStagetype(costType);
            ydTimes.add(item);
            costAnalysisReports.add(costAnalysisReport);
        }
        if (CollUtil.isNotEmpty(ydTimes)){
            ydTimeMapper.insertBatchSomeColumn(ydTimes);
        }
        costAnalysisReportMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(costAnalysisReports)){
            costAnalysisReportMapper.insertBatchSomeColumn(costAnalysisReports);
        }

        // 导入 YDCBFeeItemInfo
        String feeItemSql = "select * from YDCBFeeItemInfo";
        List<YdCbfeeiteminfo> ydInfos = new ArrayList<>();
        List<YDCBFeeItemInfoBO> bos = sqliteUtil.selectListRecord(YDCBFeeItemInfoBO.class, feeItemSql);
        for (YDCBFeeItemInfoBO bo : bos) {
            YdCbfeeiteminfo item = new YdCbfeeiteminfo();
//            item.setId(UUID.randomUUID().toString().replace("-", ""));
            item.setOid(NumberUtil.getValue(bo.getID()));
            item.setPid(NumberUtil.getValue(bo.getPID()));
            item.setCode(bo.getCode());
            item.setKeyid(NumberUtil.getValue(bo.getKeyID()));
            item.setCode(bo.getCode());
            item.setName(bo.getName());
            item.setSpec(bo.getSpec());
            item.setUnit(bo.getUnit());
            item.setDatatype(NumberUtil.getValue(bo.getDataType()));
            item.setFeetype(NumberUtil.getValue(bo.getFeeType()));
            item.setYddate(bo.getYDDate()+"");
            item.setTargetamout(bo.getTargetAmout());
            item.setTargettaxprice(bo.getTargetTaxPrice());
            item.setTargettaxtotal(bo.getTargetTaxTotal());
            item.setTargetnotaxprice(bo.getTargetNoTaxPrice());
            item.setTargetnotaxtotal(bo.getTargetNoTaxTotal());
            item.setMonthamout(bo.getMonthAmout());
            item.setMonthprice(bo.getMonthPrice());
            item.setMonthcb(bo.getMonthCb());
            item.setYstotal(bo.getYsTotal());
            item.setYzamout(bo.getYzAmout());
            item.setYznotaxtotal(bo.getYzNoTaxTotal());
            item.setYznotaxprice(bo.getYzNoTaxPrice());
            item.setCbhtamout(bo.getCbHtAmout());
            item.setCbhtnotaxprice(bo.getCbHtNoTaxPrice());
            item.setCbhtnotaxtotal(bo.getCbHtNoTaxTotal());
            item.setTargettxl(bo.getTargetTxl());
            item.setZysj(bo.getZysj());
            item.setCbsgtamout(bo.getCbSgtAmout());
            item.setCbsgtnotaxprice(bo.getCbSgtNoTaxPrice());
            item.setCbsgtnotaxtotal(bo.getCbSgtNoTaxTotal());
            item.setCbtzamout(bo.getCbTzAmout());
            item.setCbtznotaxprice(bo.getCbTzNoTaxPrice());
            item.setCbtznotaxtotal(bo.getCbTzNoTaxTotal());
            item.setCbtznotaxpricechange(bo.getCbTzNoTaxPriceChange());
            item.setCbtzamountchange(bo.getCbTzAmountChange());
            item.setTztargettxl(bo.getTzTargetTxl());
            item.setYmbtargettxl(bo.getYMBTargetTxl());
            item.setYmbzysj(bo.getYMBZysj());
            item.setTzzysj(bo.getTzZysj());
            item.setJce(bo.getJce());
            item.setHttargetzzsl(bo.getHTTargetZzsl());
            item.setHttargetsjtotal(bo.getHTTargetSjTotal());
            item.setSgttargetsjtotal(bo.getSgtTargetSjTotal());
            item.setSgttargetzzsl(bo.getSgtTargetZzsl());
            item.setTargetzzsl(bo.getTargetZzsl());
            item.setTargetsjtotal(bo.getTargetSjTotal());
            item.setSjcbtargetzzsl(bo.getSjcbTargetZzsl());
            item.setSjcbtargetsjtotal(bo.getSjcbTargetSjTotal());
            item.setJceamout(bo.getJceAmout());
            item.setJceprice(bo.getJcePrice());
            item.setJcl(bo.getJcl());
            item.setQyjcl(bo.getQYJcl());
            item.setQyjce(bo.getQYJce());
            item.setQyjceamout(bo.getQYJceAmout());
            item.setQyjceprice(bo.getQYJcePrice());
            item.setXmjce(bo.getXMJce());
            item.setXmjcl(bo.getXMJcl());
            item.setBqprice(bo.getBQPrice());
            item.setCgprice(bo.getCGPrice());
            item.setDnamout(bo.getDNAmout());
            item.setDwamout(bo.getDWAmout());
            item.setProId(proId);
            item.setStagetype(costType);
            ydInfos.add(item);
        }
        // ydcbFeeItemInfoRepository.deleteByProid(proID);
        ydCbfeeiteminfoMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydInfos)){
            ydCbfeeiteminfoMapper.insertBatchSomeColumn(ydInfos);
        }

        /** 汇总表 */
        String hzSql = "select * from YDSummaryBEIJINGSANJU";
        List<CostAnalysisHz> hzs = new ArrayList<>();
        List<YDSummaryBEIJINGSANJUBo> bjsjBos = sqliteUtil.selectListRecord(YDSummaryBEIJINGSANJUBo.class, hzSql);
        for (YDSummaryBEIJINGSANJUBo bo : bjsjBos) {
            CostAnalysisHz hz = new CostAnalysisHz();
            hz.setOid(bo.getID() + "");
            hz.setPid(bo.getPID() + "");
            hz.setProId(proId);
            hz.setStagetype(costType);
            hz.setYddate(bo.getYDDate() + "");
            hz.setCode("");
            hz.setName(bo.getName());
            hz.setHtsr(bo.getYzNoTaxTotal());
            hz.setMbcbyht(bo.getCbHtNoTaxTotal());
            hz.setMbcbsgt(bo.getCbSgtNoTaxTotal());
            hz.setMbdtbhshj(bo.getCbTzNoTaxTotal());
            hz.setMbdtltz(bo.getCbTzAmountChange());
            hz.setMbdtjtz(bo.getCbTzNoTaxPriceChange());
            hz.setMbcbtzh(bo.getTargetNoTaxTotal());
            hz.setSjcb(bo.getMonthCb());
            hz.setYkehj(bo.getJce());
            hz.setYkelyk(bo.getJceAmout());
            hz.setYkejyk(bo.getJcePrice());
            //盈亏率=()
            hz.setYkeykl(NumberUtil.divideUseProportion(bo.getJce(),bo.getYzNoTaxTotal()) + "%");
            hz.setJcqyhj(bo.getQYJce());
            hz.setJcqyljc(bo.getQYJceAmout());
            hz.setJcqyjjc(bo.getQYJcePrice());
            //节超率=(企业角度)
            hz.setJcqyjcl(bo.getQYJcl() + "%");
            hz.setJcxmjce(bo.getXMJce());

            //节超率=(项目角度)
            hz.setJcxmjcl(bo.getXMJcl()+"%");

            hz.setYkfxbq(bo.getBQPrice());
            hz.setYkfxcg(bo.getCGPrice());
            hz.setYkfxwjs(bo.getDWAmout());
            hz.setYkfxngk(bo.getDNAmout());
            hz.setYhtkdk(bo.getHTTargetSjTotal());
            hz.setSgtkdk(bo.getSgtTargetSjTotal());
            hz.setTzhkdk(bo.getTargetSjTotal());
            hz.setSjcbkdk(bo.getSjcbTargetSjTotal());
            hzs.add(hz);
        }
        // costAnalysisHzRepository.deleteByProid(proID);
        costAnalysisHzMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(hzs)){
            costAnalysisHzMapper.insertBatchSomeColumn(hzs);
        }
        // 汇总需要删除
        //ydCostAnalysListRepository.deleteByProid(proID);
        ydCostanalysisListMapper.deleteByProIdAndStagetype(proId,costType);
        List<YdCostanalysisList> moreYdList = getProHzs(hzs,proId,costType);
        if (CollUtil.isNotEmpty(moreYdList)){
            ydCostanalysisListMapper.insertBatchSomeColumn(moreYdList);
        }

        String strVersionSql = "select * from DBVersion";
        List<DBVersion> dBVersionList = sqliteUtil.selectListRecord(DBVersion.class, strVersionSql);

        DataToolFileversion toolFileDataVersion = dataToolFileversionMapper.findByCodeAndType(new DataToolFileversion(project.getCode(), costType));
        if(toolFileDataVersion==null) toolFileDataVersion = new DataToolFileversion();
        toolFileDataVersion.setCode(project.getCode());
        toolFileDataVersion.setType(costType);
        toolFileDataVersion.setFilePath(downFile.getAbsolutePath());
        toolFileDataVersion.setStatus("");
        if(CollUtil.isNotEmpty(dBVersionList)) toolFileDataVersion.setFileVersion(dBVersionList.get(0).getDBVersion());
        DataToolFileversion dataToolFileversion = dataToolFileversionMapper.selectDataToolFileversionById(toolFileDataVersion.getId());
        if (dataToolFileversion == null){
            dataToolFileversionMapper.insert(toolFileDataVersion);
        }

        String ModifyItemSql = "select * from ModifyItem";
        List<YdModifyitem> ydModifyItemList = new ArrayList<>();
        List<YDModifyItemBO> ydModifyItemBoList = sqliteUtil.selectListRecord(YDModifyItemBO.class, ModifyItemSql);
        for (YDModifyItemBO ydModifyItemBO : ydModifyItemBoList) {
            YdModifyitem ydModifyItem = new YdModifyitem();
            ydModifyItem.setOid(ydModifyItemBO.getID());
            ydModifyItem.setYstotal(ydModifyItemBO.getYsTotal());
            ydModifyItem.setTargettaxtotal(ydModifyItemBO.getTargetTaxTotal());
            ydModifyItem.setTime(ydModifyItemBO.getTime());
            ydModifyItem.setTxt(ydModifyItemBO.getTxt());
            ydModifyItem.setProId(proId);
            ydModifyItem.setStagetype(costType);
            ydModifyItemList.add(ydModifyItem);
        }
        // ydModifyItemRepository.deleteByProject(project);
        ydCbfeeiteminfoMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydModifyItemList)){
            ydModifyitemMapper.insertBatchSomeColumn(ydModifyItemList);
        }

        String cbFeeItemSql = "select * from YDCBFeeItem";
        List<YDCbFeeItemBO> ydCbFeeItemBOs = sqliteUtil.selectListRecord(YDCbFeeItemBO.class, cbFeeItemSql);
        List<YdCbfeeitem> ydCbFeeItems = new ArrayList<YdCbfeeitem>();
        for (YDCbFeeItemBO YDCbFeeItemBO : ydCbFeeItemBOs) {
            YdCbfeeitem conversion = YdCbfeeitem.convert(YDCbFeeItemBO);
            conversion.setProId(proId);
            conversion.setStagetype(costType);
            ydCbFeeItems.add(conversion);
        }
        // ydCbFeeItemRepository.deleteByProject(project);
        ydCbfeeitemMapper.deleteByProIdAndStagetype(proId,costType);
/*        if (CollUtil.isNotEmpty(ydCbFeeItems)){
            ydCbfeeitemMapper.insertBatchSomeColumn(ydCbFeeItems);
        }*/
        if (CollUtil.isNotEmpty(ydCbFeeItems)) {
            int pageNumber = 2000;
            int totalPage = (ydCbFeeItems.size() + pageNumber - 1) / pageNumber;
            for (int i = 1; i <= totalPage; i++) {
                int start = (i - 1) * pageNumber;
                int end = start + pageNumber;
                if (end > ydCbFeeItems.size()) end = ydCbFeeItems.size();
                ydCbfeeitemMapper.insertBatchSomeColumn(ydCbFeeItems.subList(start, end));
            }
        }

        String ydcbSummarySql = "select * from YDCBSummary";
        List<YDCBSummaryBO> YDCBSummaryBOs = sqliteUtil.selectListRecord(YDCBSummaryBO.class, ydcbSummarySql);
        List<YdCbsummary> YDCBSummarys = new ArrayList<YdCbsummary>();
        for (YDCBSummaryBO YDCBSummaryBO : YDCBSummaryBOs) {
            YdCbsummary conversion = YdCbsummary.convert(YDCBSummaryBO);
            conversion.setProId(proId);
            conversion.setStagetype(costType);
            YDCBSummarys.add(conversion);
        }
        // ydcbSummaryRepository.deleteByProject(project);
        ydCbsummaryMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(YDCBSummarys)){
            ydCbsummaryMapper.insertBatchSomeColumn(YDCBSummarys);
        }

        String costAnalysisSql = "select * from CostAnalysis";
        List<YDCostAnalysisBO> YDCostAnalysisBOs = sqliteUtil.selectListRecord(YDCostAnalysisBO.class, costAnalysisSql);
        List<YdCostanalysis> YDCostAnalysiss = new ArrayList<YdCostanalysis>();
        for (YDCostAnalysisBO YDCostAnalysisBO : YDCostAnalysisBOs) {
            YdCostanalysis conversion = YdCostanalysis.convert(YDCostAnalysisBO);
            conversion.setProId(proId);
            conversion.setStagetype(costType);
            YDCostAnalysiss.add(conversion);
        }
        ydCostanalysisMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(YDCostAnalysiss)){
            ydCostanalysisMapper.insertBatchSomeColumn(YDCostAnalysiss);
        }

        String cbfeeitemStandardSql = "select * from YDCBFeeItemInfoStandard";

        ydCbfeeiteminfoStandardMapper.deleteByProIdAndStagetype(proId,costType);
        List<YdCbfeeiteminfoStandard> standardList = new ArrayList<>();
        List<YDCBFeeItemInfoStandard> ydcbFeeItemInfoStandards = sqliteUtil.selectListRecord(YDCBFeeItemInfoStandard.class, cbfeeitemStandardSql);
        if (CollUtil.isNotEmpty(ydcbFeeItemInfoStandards)) {
            for (YDCBFeeItemInfoStandard ydcbFeeItemInfoStandard : ydcbFeeItemInfoStandards) {
                YdCbfeeiteminfoStandard convert = YDCBFeeItemInfoStandard.convert(ydcbFeeItemInfoStandard);
                convert.setProId(proId);
                convert.setStagetype(costType);
                standardList.add(convert);
            }
            ydCbfeeiteminfoStandardMapper.insertBatchSomeColumn(standardList);
        }


        String ydbqItemMateSql = "select * from YDBQItemMate";
        List<YDBQItemMateBo> ydbqItemMateBos = sqliteUtil.selectListRecord(YDBQItemMateBo.class, ydbqItemMateSql);
        List<YdBqitemMate> ydBqitemMateList = new ArrayList<>();
        for (YDBQItemMateBo ydbqItemMateBo : ydbqItemMateBos) {
            YdBqitemMate convert = YDBQItemMateBo.convert(ydbqItemMateBo);
            convert.setProId(proId);
            convert.setStagetype(costType);
            ydBqitemMateList.add(convert);
        }
        ydBqitemMateMapper.deleteByProIdAndStagetype(proId,costType);
/*        if (CollUtil.isNotEmpty(ydBqitemMateList)) {
            ydBqitemMateMapper.insertBatchSomeColumn(ydBqitemMateList);
        }*/
        if (CollUtil.isNotEmpty(ydBqitemMateList)) {
            int pageNumber = 2000;
            int totalPage = (ydBqitemMateList.size() + pageNumber - 1) / pageNumber;
            for (int i = 1; i <= totalPage; i++) {
                int start = (i - 1) * pageNumber;
                int end = start + pageNumber;
                if (end > ydBqitemMateList.size()) end = ydBqitemMateList.size();
                ydBqitemMateMapper.insertBatchSomeColumn(ydBqitemMateList.subList(start, end));
            }
        }


        String ydsummarySql = "select * from YDSummary";
        List<YDSummaryBo> ydSummaryBos = sqliteUtil.selectListRecord(YDSummaryBo.class, ydsummarySql);
        List<YdSummary> ydSummaryList = new ArrayList<>();
        for (YDSummaryBo ydSummaryBo : ydSummaryBos) {
            YdSummary convert = YDSummaryBo.convert(ydSummaryBo);
            convert.setProId(proId);
            convert.setStagetype(costType);
            ydSummaryList.add(convert);
        }
        ydSummaryMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydSummaryList)) {
            ydSummaryMapper.insertBatchSomeColumn(ydSummaryList);
        }

        String ydcbfeeitemMateSql = "select * from YDCBFeeItemMate";
        List<YDCBFeeitemMateBo> ydcbFeeitemMateBos = sqliteUtil.selectListRecord(YDCBFeeitemMateBo.class, ydcbfeeitemMateSql);
        List<YdcbFeeitemMate> ydcbFeeitemMateList = new ArrayList<>();
        for (YDCBFeeitemMateBo ydcbFeeitemMateBo : ydcbFeeitemMateBos) {
            YdcbFeeitemMate convert = YDCBFeeitemMateBo.convert(ydcbFeeitemMateBo);
            convert.setProId(proId);
            convert.setStagetype(costType);
            ydcbFeeitemMateList.add(convert);
        }
        ydcbFeeitemMateMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydcbFeeitemMateList)) {
            ydcbFeeitemMateMapper.insertBatchSomeColumn(ydcbFeeitemMateList);
        }

        // CbHzInfo
        String cbHzInfoSql = "select * from CbHzInfo";
        List<CbHzInfoBo> cbHzInfoBos = sqliteUtil.selectListRecord(CbHzInfoBo.class, cbHzInfoSql);
        List<EcoCbhzinfo> ecoCbhzinfoList = new ArrayList<>();
        for (CbHzInfoBo cbHzInfoBo : cbHzInfoBos) {
            EcoCbhzinfo resBo =  CbHzInfoBo.convert(cbHzInfoBo);
            resBo.setProId(proId);
            resBo.setStagetype(costType);
            ecoCbhzinfoList.add(resBo);
        }
        ecoCbhzinfoMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ecoCbhzinfoList)) {
            ecoCbhzinfoMapper.insertBatchSomeColumn(ecoCbhzinfoList);
        }

        // CbHzInfo
        String ydczSummarySql = "select * from YDCZSummary";
        List<YDCBCzSummaryBo> ydcbCzSummaryBos = sqliteUtil.selectListRecord(YDCBCzSummaryBo.class, ydczSummarySql);
        List<YdczSummary> ydczSummaries = new ArrayList<>();
        for (YDCBCzSummaryBo ydcbCzSummaryBo : ydcbCzSummaryBos) {
            YdczSummary resBo =  YDCBCzSummaryBo.convert(ydcbCzSummaryBo);
            resBo.setProId(proId);
            resBo.setStagetype(costType);
            ydczSummaries.add(resBo);
        }
        ydczSummaryMapper.deleteByProIdAndStagetype(proId,costType);
        if (CollUtil.isNotEmpty(ydczSummaries)) {
            ydczSummaryMapper.insertBatchSomeColumn(ydczSummaries);
        }


//        if (CCBConstants.CCB_TYPE.CZTJ.getCode().equals(costType)) {
//            // 产值上传   处理一部分非 YDCB开头的表
//
//        }
        uploadCZTJ(sqliteUtil,costType,proId);
    }

    private void uploadCZTJ(SqliteUtil sqliteUtil,String type,String proId) {
        // 处理
        String strSql = "select hz.* from BQItem hz";
        List<BQItemBO> BQItemBOList = sqliteUtil.selectListRecord(BQItemBO.class, strSql);
        List<EcoBqitem> bQItemList =new ArrayList<>();
        for (BQItemBO bQItemBO : BQItemBOList) {
            EcoBqitem bqItem=new EcoBqitem();
            bqItem.setBqitemid(bQItemBO.getID());
            bqItem.setBqitempid(bQItemBO.getPID());
            bqItem.setCode(bQItemBO.getCode());
            bqItem.setDescription(bQItemBO.getDescription());
            bqItem.setSpec(bQItemBO.getSpec());
            bqItem.setUnit(bQItemBO.getUnit());
            bqItem.setQuantity(bQItemBO.getQuantity());
            bqItem.setWorkscope(bQItemBO.getWorkScope());
            bqItem.setLaborrate(bQItemBO.getLaborRate());
            bqItem.setMaterialrate(bQItemBO.getMaterialRate());
            bqItem.setMachinerate(bQItemBO.getMachineRate());
            bqItem.setOverheadrate(bQItemBO.getOverheadRate());
            bqItem.setProfitrate(bQItemBO.getProfitRate());
            bqItem.setLevyfeerate(bQItemBO.getLevyFeeRate());
            bqItem.setTaxrate(bQItemBO.getTaxRate());
            bqItem.setRate(bQItemBO.getRate());
            bqItem.setItemtype(bQItemBO.getItemType());
            bqItem.setBidnodeid(bQItemBO.getBidNodeID());
            bqItem.setDwbidnodeid(bQItemBO.getDwBidNodeID());
            bqItem.setFbms(bQItemBO.getFbms());
            bqItem.setQdtype(bQItemBO.getQdType());
            bqItem.setBackcolor(bQItemBO.getBackColor());
            bqItem.setPx(bQItemBO.getPX());
            bqItem.setOrgfb(bQItemBO.getOrgFB());
            bqItem.setStandardfb(bQItemBO.getStandardFB());
            bqItem.setOrgname(bQItemBO.getOrgName());
            bqItem.setIscf(bQItemBO.getIsCf()?"Y":"N");
            bqItem.setIsadded(bQItemBO.getIsAdded()?"Y":"N");
            bqItem.setTargetamountexp(bQItemBO.getTargetAmountExp());
            bqItem.setZcmaterialrate(bQItemBO.getZcMaterialRate());
            bqItem.setFcmaterialrate(bQItemBO.getFcMaterialRate());
            bqItem.setZymachinerate(bQItemBO.getZyMachineRate());
            bqItem.setDxmachinerate(bQItemBO.getDxMachineRate());
            bqItem.setQtmachinerate(bQItemBO.getQtMachineRate());
            bqItem.setXjlaborrate(bQItemBO.getXJLaborRate());
            bqItem.setXjmaterialrate(bQItemBO.getXJMaterialRate());
            bqItem.setXjmachinerate(bQItemBO.getXJMachineRate());
            bqItem.setXjrate(bQItemBO.getXJRate());
            bqItem.setXjquantity(bQItemBO.getXJQuantity());
            bqItem.setSfzj(bQItemBO.getSfZj()?"Y":"N");
            bqItem.setContractcode(bQItemBO.getContractCode());
            bqItem.setIsnewdata(bQItemBO.getIsNewData());
            bqItem.setFcrate(bQItemBO.getFcRate());
            bqItem.setQtjxrate(bQItemBO.getQTjxRate());
            bqItem.setGlrate(bQItemBO.getGlRate());
            bqItem.setLrrate(bQItemBO.getLrRate());
            bqItem.setCategoryid(bQItemBO.getCategoryID());
            bqItem.setCbtotal(bQItemBO.getCBTotal());
            bqItem.setOriginalunit(bQItemBO.getOriginalUnit());
            bqItem.setProId(proId);
            bqItem.setStagetype(type);
            bQItemList.add(bqItem);
        }
        bqitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(bQItemList)) {
            bqitemMapper.insertBatchSomeColumn(bQItemList);
        }

        strSql = "select hz.* from MeasureItem hz";
        List<MeasureItemBO> measureItemBOList = sqliteUtil.selectListRecord(MeasureItemBO.class, strSql);
        List<EcoMeasureitem> measureItemList =new ArrayList<>();
        for (MeasureItemBO measureItemBO : measureItemBOList) {
            EcoMeasureitem measureItem=new EcoMeasureitem();
            measureItem.setMeasureitemid(measureItemBO.getID());
            measureItem.setMeasureitempid(measureItemBO.getPID());
            measureItem.setCode(measureItemBO.getCode());
            measureItem.setDescription(measureItemBO.getDescription());
            measureItem.setSpec(measureItemBO.getSpec());
            measureItem.setUnit(measureItemBO.getUnit());
            measureItem.setQuantity(measureItemBO.getQuantity());
            measureItem.setWorkscope(measureItemBO.getWorkScope());
            measureItem.setLaborrate(measureItemBO.getLaborRate());
            measureItem.setMaterialrate(measureItemBO.getMaterialRate());
            measureItem.setMachinerate(measureItemBO.getMachineRate());
            measureItem.setOverheadrate(measureItemBO.getOverheadRate());
            measureItem.setProfitrate(measureItemBO.getProfitRate());
            measureItem.setLevyfeerate(measureItemBO.getLevyFeeRate());
            measureItem.setTaxrate(measureItemBO.getTaxRate());
            measureItem.setRate(measureItemBO.getRate());
            measureItem.setItemtype(measureItemBO.getItemType());
            measureItem.setBidnodeid(measureItemBO.getBidNodeID());
            measureItem.setFbms(measureItemBO.getFbms());
            measureItem.setQdtype(measureItemBO.getQdType());
            measureItem.setBackcolor(measureItemBO.getBackColor());
            measureItem.setPx(measureItemBO.getPX());
            measureItem.setOrgfb(measureItemBO.getOrgFB());
            measureItem.setStandardfb(measureItemBO.getStandardFB());
            measureItem.setOrgname(measureItemBO.getOrgName());
            measureItem.setIscf(measureItemBO.getIsCf()?"Y":"N");
            measureItem.setIsadded(measureItemBO.getIsAdded()?"Y":"N");
            measureItem.setTargetamountexp(measureItemBO.getTargetAmountExp());
            measureItem.setZcmaterialrate(measureItemBO.getZcMaterialRate());
            measureItem.setFcmaterialrate(measureItemBO.getFcMaterialRate());
            measureItem.setZymachinerate(measureItemBO.getZyMachineRate());
            measureItem.setDxmachinerate(measureItemBO.getDxMachineRate());
            measureItem.setQtmachinerate(measureItemBO.getQtMachineRate());
            measureItem.setXjlaborrate(measureItemBO.getXJLaborRate());
            measureItem.setXjmaterialrate(measureItemBO.getXJMaterialRate());
            measureItem.setXjmachinerate(measureItemBO.getXJMachineRate());
            measureItem.setXjrate(measureItemBO.getXJRate());
            measureItem.setXjquantity(measureItemBO.getXJQuantity());
            measureItem.setSfzj(measureItemBO.getSfZj()?"Y":"N");
            measureItem.setContractcode(measureItemBO.getContractCode());
            measureItem.setIsnewdata(measureItemBO.getIsNewData());
            measureItem.setFcrate(measureItemBO.getFcRate());
            measureItem.setQtjxrate(measureItemBO.getQTjxRate());
            measureItem.setGlrate(measureItemBO.getGlRate());
            measureItem.setLrrate(measureItemBO.getLrRate());
            measureItem.setCategoryid(measureItemBO.getCategoryID());
            measureItem.setCbtotal(measureItemBO.getCBTotal());
            measureItem.setOriginalunit(measureItemBO.getOriginalUnit());
            measureItem.setProId(proId);
            measureItem.setStagetype(type);
            measureItemList.add(measureItem);
        }
        measureitemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(measureItemList)) {
            measureitemMapper.insertBatchSomeColumn(measureItemList);
        }

        strSql = "select hz.* from OtherItem hz";
        List<OtherItemBo> otherItemBos = sqliteUtil.selectListRecord(OtherItemBo.class, strSql);
        List<EcoOtheritem> otherItems = new ArrayList<>();
        for (OtherItemBo oib : otherItemBos) {
            EcoOtheritem oi = new EcoOtheritem();
            oi.setOid(oib.getID());
            oi.setOpid(oib.getPID());
            oi.setOrdcode(oib.getOrdCode());
            oi.setName(oib.getName());
            oi.setUnit(oib.getUnit());
            oi.setQuantity(oib.getQuantity());
            oi.setCalcbase(oib.getCalcBase());
            oi.setCalctotal(oib.getCalcTotal());
            oi.setRate(oib.getRate());
            oi.setTotal(oib.getTotal());
            oi.setKind(oib.getKind());
            oi.setBidnodeid(oib.getBidNodeID());
            oi.setContractcode(oib.getContractCode());
            oi.setIsnewdata(oib.getIsNewData());
            oi.setCbtotal(oib.getCBTotal());
            oi.setOriginalunit(oib.getOriginalUnit());
            oi.setIslssc(oib.getLsSc() + "");
            oi.setItemtype(oib.getItemType());
            oi.setWbscategory(oib.getWBSCategory());
            oi.setStagetype(type);
            oi.setProId(proId);
            otherItems.add(oi);
        }
        otheritemMapper.deleteByProIdAndStagetype(proId,type);
        if (CollUtil.isNotEmpty(otherItems)) {
            otheritemMapper.insertBatchSomeColumn(otherItems);
        }
    }



    /**
     * 因上传是往期也上传所以需要处理多个
     * @param hzs
     * @param proId
     * @return
     */
    private List<YdCostanalysisList> getProHzs(List<CostAnalysisHz> hzs,String proId,String costType) {
        List<YdCostanalysisList> resultList = new ArrayList<>();
        Map<String, List<CostAnalysisHz>> ydDateMap =
                hzs.stream().collect(Collectors.groupingBy(CostAnalysisHz::getYddate));
        Set<Map.Entry<String, List<CostAnalysisHz>>> entries = ydDateMap.entrySet();
        for (Map.Entry<String, List<CostAnalysisHz>> entry : entries) {
            String key = entry.getKey();
            List<CostAnalysisHz> value = entry.getValue();
            YdCostanalysisList proHz = getProHz(value);
            proHz.setProId(proId);
            proHz.setStagetype(costType);
            proHz.setYddate(key);
            resultList.add(proHz);
        }
        return resultList;
    }
    private YdCostanalysisList getProHz(List<CostAnalysisHz> hzs) {
        BigDecimal htsr = BigDecimal.ZERO;
        BigDecimal yhtmbcb = BigDecimal.ZERO;
        BigDecimal sgtmbcb = BigDecimal.ZERO;
        BigDecimal mbtzbhshj = BigDecimal.ZERO;
        BigDecimal mbtzltz = BigDecimal.ZERO;
        BigDecimal mbtzjtz = BigDecimal.ZERO;
        BigDecimal mbcbtzh = BigDecimal.ZERO;
        BigDecimal sjcb = BigDecimal.ZERO;
        BigDecimal ykykehj = BigDecimal.ZERO;
        BigDecimal ykykelyk = BigDecimal.ZERO;
        BigDecimal ykykejyk = BigDecimal.ZERO;
        BigDecimal ykykl = BigDecimal.ZERO;
        BigDecimal jcqyhj = BigDecimal.ZERO;
        BigDecimal jcqyljc = BigDecimal.ZERO;
        BigDecimal jcqyjjc = BigDecimal.ZERO;
        BigDecimal jcqyjcl = BigDecimal.ZERO;
        BigDecimal jcxmjce = BigDecimal.ZERO;
        BigDecimal jcxmjcl = BigDecimal.ZERO;
        BigDecimal ykfxbq = BigDecimal.ZERO;
        BigDecimal ykfxcg = BigDecimal.ZERO;
        BigDecimal ykfxwjs = BigDecimal.ZERO;
        BigDecimal ykfxngk = BigDecimal.ZERO;
        for (CostAnalysisHz hz : hzs) {
            htsr = NumberUtil.add(htsr,hz.getHtsr());
            yhtmbcb = NumberUtil.add(yhtmbcb,hz.getMbcbyht());
            sgtmbcb = NumberUtil.add(sgtmbcb,hz.getMbcbsgt());
            mbtzbhshj = NumberUtil.add(mbtzbhshj,hz.getMbdtbhshj());
            mbtzltz = NumberUtil.add(mbtzltz,hz.getMbdtltz());
            mbtzjtz = NumberUtil.add(mbtzjtz,hz.getMbdtjtz());
            mbcbtzh = NumberUtil.add(mbcbtzh,hz.getMbcbtzh());
            sjcb = NumberUtil.add(sjcb,hz.getSjcb());
            ykykehj = NumberUtil.add(ykykehj,hz.getYkehj());
            ykykelyk = NumberUtil.add(ykykelyk,hz.getYkelyk());
            ykykejyk = NumberUtil.add(ykykejyk,hz.getYkejyk());
            jcqyhj = NumberUtil.add(jcqyhj,hz.getJcqyhj());
            jcqyljc = NumberUtil.add(jcqyljc,hz.getJcqyljc());
            jcqyjjc = NumberUtil.add(jcqyjjc,hz.getJcqyjjc());
            jcxmjce = NumberUtil.add(jcxmjce,hz.getJcxmjce());
            ykfxbq = NumberUtil.add(ykfxbq,hz.getYkfxbq());
            ykfxcg = NumberUtil.add(ykfxcg,hz.getYkfxcg());
            ykfxwjs = NumberUtil.add(ykfxwjs,hz.getYkfxwjs());
            ykfxngk = NumberUtil.add(ykfxngk,hz.getYkfxngk());
        }
        /**
         * 	企业节超率 :	节超（企业角度） 节超额 合计 / 目标成本 施工图
         * 	盈亏率 :	盈亏 盈亏额 合计 / 合同收入
         */
        jcqyjcl = NumberUtil.divideUseProportion(jcqyhj, sgtmbcb);
        jcxmjcl = NumberUtil.divideUseProportion(jcxmjce, sgtmbcb);
        ykykl = NumberUtil.divideUseProportion(ykykehj, htsr);

        YdCostanalysisList analysis = new YdCostanalysisList();
//        analysis.setId(UUID.randomUUID().toString().replace("-", ""));
        analysis.setHtsr(htsr);
        analysis.setYhtmbcb(yhtmbcb);
        analysis.setSgtmbcb(sgtmbcb);
        analysis.setMbtzbhshj(mbtzbhshj);
        analysis.setMbtzltz(mbtzltz);
        analysis.setMbtzjtz(mbtzjtz);
        analysis.setMbcbtzh(mbcbtzh);
        analysis.setSjcb(sjcb);
        analysis.setYkykehj(ykykehj);
        analysis.setYkykelyk(ykykelyk);
        analysis.setYkykejyk(ykykejyk);
        analysis.setYkykl(ykykl);
        analysis.setJcqyhj(jcqyhj);
        analysis.setJcqyljc(jcqyljc);
        analysis.setJcqyjjc(jcqyjjc);
        analysis.setJcqyjcl(jcqyjcl);
        analysis.setJcxmjce(jcxmjce);
        analysis.setJcxmjcl(jcxmjcl);
        analysis.setYkfxbq(ykfxbq);
        analysis.setYkfxcg(ykfxcg);
        analysis.setYkfxwjs(ykfxwjs);
        analysis.setYkfxngk(ykfxngk);
        return analysis;
    }
}
